package com.cloudsigns.factorymanager2.engineering.model;

import android.text.TextUtils;
import android.util.Log;

import com.cloudsigns.factorymanager2.MyApplicaton;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringBatchInstallationOrderBean;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringDailyFeedBackBean;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringInstallationOrderBean;
import com.cloudsigns.factorymanager2.engineering.bean.OrderParentBean;
import com.cloudsigns.factorymanager2.engineering.utils.EngineeringUtil;
import com.cloudsigns.factorymanager2.project.bean.ProductBean;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;
import com.cloudsigns.factorymanager2.project.utils.DateUtil;
import com.cloudsigns.factorymanager2.project.utils.ProjectUtil;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tony on 2018/4/1.
 */

public class EngineeringInstallOrderDetailModel implements IEngineeringInstallOrderDetailModel {

    @Override
    public void getEngineeringInstallOrderDetail(final String orderId, final String itemId, final long feedbackDate, final OnEngineeringInstallOrderDetailListener engineeringInstallOrderDetailListener) {
        new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    String url = ProjectUtil.ENGINEERING_INSTALLATION_ORDER_DETAIL + "?orderId=" + orderId;
                    if (!TextUtils.isEmpty(itemId))
                        url = url + "&itemId=" + itemId;

                    if (feedbackDate > 0)
                        url = url + "&feedbackDate=" + feedbackDate;

                    HttpClient client = new DefaultHttpClient();
                    HttpGet httpGet = new HttpGet(url);

                    HttpResponse response;

                    httpGet.addHeader("token", MyApplicaton.getApplication().getToken());
                    httpGet.addHeader(HTTP.CONTENT_TYPE, ConstantUtil.CONTENT_TYPE);


                    response = client.execute(httpGet);
                    String result = EntityUtils.toString(response.getEntity(), "UTF-8").trim();
                    Log.e("EngineeringInstallOrder", "result=" + result);
                    JSONObject json = new JSONObject(result);
                    String code = json.getString("code");
                    if (null != engineeringInstallOrderDetailListener) {
                        if (code.equals(EngineeringUtil.HTTP_SUCCESSED_COD)) {
                            JSONObject dataJsonObj = new JSONObject(json.getString("data"));


                            EngineeringInstallationOrderBean orderBean = new EngineeringInstallationOrderBean();

                            String adminConfirmCompleteDate = dataJsonObj.getString("adminConfirmCompleteDate");
                            if (!TextUtils.isEmpty(adminConfirmCompleteDate) && !adminConfirmCompleteDate.equals("null")) {
                                orderBean.setAdminConfirmCompleteDate(Long.parseLong(adminConfirmCompleteDate));
                            }

                            orderBean.setAssignReceiveAccountId(dataJsonObj.getString("assignReceiveAccountId"));
                            orderBean.setAssignReceiveAccountName(dataJsonObj.getString("assignReceiveAccountName"));

                            String assignReceiveOrderTimeStr = dataJsonObj.getString("assignReceiveOrderTime");
                            if (!TextUtils.isEmpty(assignReceiveOrderTimeStr) && !assignReceiveOrderTimeStr.equals("null")) {
                                orderBean.setAssignReceiveOrderTime(Long.parseLong(assignReceiveOrderTimeStr));
                            }
                            String assignStatusStr = dataJsonObj.getString("assignStatus");
                            if (!TextUtils.isEmpty(assignStatusStr)) {
                                if (assignStatusStr.equals("CREATED")) {
                                    orderBean.setAssignStatus(CommonEnum.AssignStatus.CREATED);
                                } else if (assignStatusStr.equals("EDITED")) {
                                    orderBean.setAssignStatus(CommonEnum.AssignStatus.EDITED);
                                } else if (assignStatusStr.equals("SEND")) {
                                    orderBean.setAssignStatus(CommonEnum.AssignStatus.SEND);
                                } else if (assignStatusStr.equals("RECEIVED")) {
                                    orderBean.setAssignStatus(CommonEnum.AssignStatus.RECEIVED);
                                } else if (assignStatusStr.equals("RETURNED")) {
                                    orderBean.setAssignStatus(CommonEnum.AssignStatus.RETURNED);
                                } else if (assignStatusStr.equals("COMPLETED")) {
                                    orderBean.setAssignStatus(CommonEnum.AssignStatus.COMPLETED);
                                }


                            }

                            String beginDateStr = dataJsonObj.getString("beginDate");
                            if (!TextUtils.isEmpty(beginDateStr) && !beginDateStr.equals("null")) {
                                orderBean.setBeginDate(Long.parseLong(beginDateStr));
                            }

                            orderBean.setCompanyId(dataJsonObj.getString("companyId"));
                            orderBean.setCompanyId(dataJsonObj.getString("companyName"));

                            String completeCloseUpImageListArrStr = dataJsonObj.getString("completeCloseUpImageList");
                            if (null != completeCloseUpImageListArrStr && !completeCloseUpImageListArrStr.equals("null") && !TextUtils.isEmpty(completeCloseUpImageListArrStr)) {
                                JSONArray completeCloseUpImageListArr = new JSONArray(completeCloseUpImageListArrStr);

                                List<String> picUrlLs = new ArrayList<String>();
                                for (int i = 0; i < completeCloseUpImageListArr.length(); i++) {
                                    picUrlLs.add(completeCloseUpImageListArr.getString(i));
                                }
                                orderBean.setCompleteCloseUpImageList(picUrlLs);
                            }

                            String completeImageListArrStr = dataJsonObj.getString("completeImageList");
                            if (null != completeImageListArrStr && !completeImageListArrStr.equals("null") && !TextUtils.isEmpty(completeImageListArrStr)) {
                                JSONArray completeImageListArrStrArr = new JSONArray(completeImageListArrStr);

                                List<String> picUrlLs = new ArrayList<String>();
                                for (int i = 0; i < completeImageListArrStrArr.length(); i++) {
                                    picUrlLs.add(completeImageListArrStrArr.getString(i));
                                }
                                orderBean.setCompleteImageList(picUrlLs);
                            }

                            String completeOtherImageListArrStr = dataJsonObj.getString("completeOtherImageList");
                            if (null != completeOtherImageListArrStr && !completeOtherImageListArrStr.equals("null") && !TextUtils.isEmpty(completeOtherImageListArrStr)) {
                                JSONArray ompleteOtherImageListArr = new JSONArray(completeImageListArrStr);

                                List<String> picUrlLs = new ArrayList<String>();
                                for (int i = 0; i < ompleteOtherImageListArr.length(); i++) {
                                    picUrlLs.add(ompleteOtherImageListArr.getString(i));
                                }
                                orderBean.setCompleteOtherImageList(picUrlLs);
                            }


                            String completeStatusStr = dataJsonObj.getString("completeStatus");
                            if (!TextUtils.isEmpty(completeStatusStr) && !completeStatusStr.equals("null")) {
                                if (completeStatusStr.equals("WORKING")) {
                                    orderBean.setCompleteStatus(CommonEnum.CompleteStatus.WORKING);
                                } else if (completeStatusStr.equals("WORKER_COMPLETE")) {
                                    orderBean.setCompleteStatus(CommonEnum.CompleteStatus.WORKER_COMPLETE);
                                } else if (completeStatusStr.equals("ADMIN_COMPLETE")) {
                                    orderBean.setCompleteStatus(CommonEnum.CompleteStatus.ADMIN_COMPLETE);
                                } else if (completeStatusStr.equals("SUPERADMIN_COMPLETE")) {
                                    orderBean.setCompleteStatus(CommonEnum.CompleteStatus.SUPERADMIN_COMPLETE);
                                }

                            }

                            String completeDateStr = dataJsonObj.getString("completeDate");
                            if (!TextUtils.isEmpty(completeDateStr) && !completeDateStr.equals("null")) {
                                orderBean.setCompleteDate(Long.parseLong(completeDateStr));
                            }

                            String createDateStr = dataJsonObj.getString("createDate");
                            if (!TextUtils.isEmpty(createDateStr) && !createDateStr.equals("null")) {
                                orderBean.setCreateDate(Long.parseLong(createDateStr));
                            }

                            orderBean.setCreateOrderAccountId(dataJsonObj.getString("createOrderAccountId"));
                            orderBean.setCreateOrderAccountName(dataJsonObj.getString("createOrderAccountName"));
                            orderBean.setEngineeringAddress(dataJsonObj.getString("engineeringAddress"));

                            JSONArray engineeringDailyFeedbackListJsonArr = dataJsonObj.getJSONArray("engineeringDailyFeedbackList");
                            if (null != engineeringDailyFeedbackListJsonArr) {
                                List<EngineeringDailyFeedBackBean> dailyFeedBackBeenList = new ArrayList<EngineeringDailyFeedBackBean>();

                                for (int i = 0; i < engineeringDailyFeedbackListJsonArr.length(); i++) {
                                    JSONObject engineeringDailyFeedbackListJsonObj = (JSONObject) engineeringDailyFeedbackListJsonArr.get(i);
                                    EngineeringDailyFeedBackBean engineeringDailyFeedBackBean = new EngineeringDailyFeedBackBean();

                                    engineeringDailyFeedBackBean.setAccountId(engineeringDailyFeedbackListJsonObj.getString("accountId"));
                                    engineeringDailyFeedBackBean.setAccountName(engineeringDailyFeedbackListJsonObj.getString("accountName"));
                                    engineeringDailyFeedBackBean.setAdvice(engineeringDailyFeedbackListJsonObj.getString("advice"));
                                    engineeringDailyFeedBackBean.setCompleteUnusualAccountId(engineeringDailyFeedbackListJsonObj.getString("completeUnusualAccountId"));
                                    engineeringDailyFeedBackBean.setConfirmCompleteUnusualAccountName(engineeringDailyFeedbackListJsonObj.getString("completeUnusualAccountName"));
                                    String completeUnusualDateStr = engineeringDailyFeedbackListJsonObj.getString("completeUnusualDate");
                                    if (!TextUtils.isEmpty(completeUnusualDateStr) && !completeUnusualDateStr.equals("null")) {
                                        engineeringDailyFeedBackBean.setCompleteUnusualDate(Long.parseLong(completeUnusualDateStr));
                                    }
                                    engineeringDailyFeedBackBean.setCompleteUnusualDesc(engineeringDailyFeedbackListJsonObj.getString("completeUnusualDesc"));
                                    engineeringDailyFeedBackBean.setConfirmCompleteUnusualAccountId(engineeringDailyFeedbackListJsonObj.getString("confirmCompleteUnusualAccountId"));
                                    engineeringDailyFeedBackBean.setConfirmCompleteUnusualAccountName(engineeringDailyFeedbackListJsonObj.getString("confirmCompleteUnusualAccountName"));
                                    String confirmCompleteUnusualDateStr = engineeringDailyFeedbackListJsonObj.getString("confirmCompleteUnusualDate");
                                    if (!TextUtils.isEmpty(confirmCompleteUnusualDateStr) && !confirmCompleteUnusualDateStr.equals("null")) {
                                        engineeringDailyFeedBackBean.setConfirmCompleteUnusualDate(Long.parseLong(confirmCompleteUnusualDateStr));
                                    }
                                    engineeringDailyFeedBackBean.setContentDesc(engineeringDailyFeedbackListJsonObj.getString("contentDesc"));
                                    String damageNumberStr = engineeringDailyFeedbackListJsonObj.getString("damageNumber");
                                    if (null != damageNumberStr && !TextUtils.isEmpty(damageNumberStr) && !"null".equals(damageNumberStr)) {
                                        engineeringDailyFeedBackBean.setDamageNumber(Integer.parseInt(damageNumberStr));
                                    }
                                    engineeringDailyFeedBackBean.setDamageProduct(engineeringDailyFeedbackListJsonObj.getString("damageProduct"));
                                    String delayDaysStr = engineeringDailyFeedbackListJsonObj.getString("delayDays");
                                    if (null != delayDaysStr && !TextUtils.isEmpty(delayDaysStr) && !"null".equals(delayDaysStr)) {
                                        engineeringDailyFeedBackBean.setDelayDays(Integer.parseInt(delayDaysStr));
                                    }

                                    String feedbackDateStr = engineeringDailyFeedbackListJsonObj.getString("feedbackDate");
                                    if (!TextUtils.isEmpty(feedbackDateStr) && !feedbackDateStr.equals("null")) {
                                        String date = DateUtil.getYyyy_Mm_Dd(Long.parseLong(feedbackDateStr));
                                        engineeringDailyFeedBackBean.setFeedbackDate(Long.parseLong(feedbackDateStr));
                                    }

                                    String handleDate = engineeringDailyFeedbackListJsonObj.getString("handleDate");
                                    if (!TextUtils.isEmpty(handleDate) && !handleDate.equals("null")) {
                                        engineeringDailyFeedBackBean.setHandleDate(Long.parseLong(handleDate));
                                    }
                                    engineeringDailyFeedBackBean.setHandleInfo(engineeringDailyFeedbackListJsonObj.getString("handleInfo"));
                                    engineeringDailyFeedBackBean.setHandlerAccountId(engineeringDailyFeedbackListJsonObj.getString("handlerAccountId"));
                                    engineeringDailyFeedBackBean.setHandlerAccountName(engineeringDailyFeedbackListJsonObj.getString("handlerAccountName"));
                                    engineeringDailyFeedBackBean.setId(engineeringDailyFeedbackListJsonObj.getString("id"));

                                    String imgUrlListJsonArrStr = engineeringDailyFeedbackListJsonObj.getString("imgUrlList");
                                    if (null != imgUrlListJsonArrStr && !imgUrlListJsonArrStr.equals("null") && !TextUtils.isEmpty(imgUrlListJsonArrStr)) {
                                        JSONArray imgUrlListJsonArr = new JSONArray(imgUrlListJsonArrStr);
                                        List<String> imgUrlList = new ArrayList<String>();
                                        for (int j = 0; j < imgUrlListJsonArr.length(); j++) {
                                            String str = (String) imgUrlListJsonArr.get(j);
                                            imgUrlList.add(str);
                                        }
                                        engineeringDailyFeedBackBean.setImgUrlList(imgUrlList);
                                    }


                                    engineeringDailyFeedBackBean.setItemId(engineeringDailyFeedbackListJsonObj.getString("itemId"));
                                    String normalType = engineeringDailyFeedbackListJsonObj.getString("normalType");
                                    if (null != normalType) {
                                        if (normalType.equals("CONSTRUCT")) {
                                            engineeringDailyFeedBackBean.setNormalType(CommonEnum.NormalSubType.CONSTRUCT);
                                        } else if (normalType.equals("LOGISTICS")) {
                                            engineeringDailyFeedBackBean.setNormalType(CommonEnum.NormalSubType.LOGISTICS);
                                        }
                                    }


                                    engineeringDailyFeedBackBean.setOmitContent(engineeringDailyFeedbackListJsonObj.getString("omitContent"));
                                    String omitNumberStr = engineeringDailyFeedbackListJsonObj.getString("omitNumber");
                                    if (null != omitNumberStr && !TextUtils.isEmpty(omitNumberStr) && !"null".equals(omitNumberStr)) {
                                        engineeringDailyFeedBackBean.setOmitNumber(Integer.parseInt(omitNumberStr));
                                    }

                                    String otherImgUrlListJsonArrStr = engineeringDailyFeedbackListJsonObj.getString("otherImgUrlList");
                                    if (null != otherImgUrlListJsonArrStr && !otherImgUrlListJsonArrStr.equals("null") && !TextUtils.isEmpty(otherImgUrlListJsonArrStr)) {
                                        JSONArray otherImgUrlListJsonArr = new JSONArray(otherImgUrlListJsonArrStr);
                                        List<String> imgUrlList = new ArrayList<String>();
                                        for (int j = 0; j < otherImgUrlListJsonArr.length(); j++) {
                                            String str = (String) otherImgUrlListJsonArr.get(j);
                                            imgUrlList.add(str);
                                        }
                                        engineeringDailyFeedBackBean.setOtherImgUrlList(imgUrlList);
                                    }


                                    engineeringDailyFeedBackBean.setStatus(engineeringDailyFeedbackListJsonObj.getString("status"));
                                    String subTypeStr = engineeringDailyFeedbackListJsonObj.getString("subType");
                                    if (!TextUtils.isEmpty(subTypeStr)) {
                                        if (subTypeStr.equals("DAMAGE")) {
                                            engineeringDailyFeedBackBean.setSubType(CommonEnum.SubType.DAMAGE);
                                        } else if (subTypeStr.equals("DELAY")) {
                                            engineeringDailyFeedBackBean.setSubType(CommonEnum.SubType.DELAY);
                                        } else if (subTypeStr.equals("INSTALL_UNUSUAL")) {
                                            engineeringDailyFeedBackBean.setSubType(CommonEnum.SubType.INSTALL_UNUSUAL);
                                        } else if (subTypeStr.equals("OMIT")) {
                                            engineeringDailyFeedBackBean.setSubType(CommonEnum.SubType.OMIT);
                                        }

                                    }
                                    String typeStr = engineeringDailyFeedbackListJsonObj.getString("type");
                                    if (!TextUtils.isEmpty(typeStr)) {
                                        if (typeStr.equals("NORMAL")) {
                                            engineeringDailyFeedBackBean.setType(CommonEnum.FeedBackType.NORMAL);
                                        } else if (typeStr.equals("UNUSUAL")) {
                                            engineeringDailyFeedBackBean.setType(CommonEnum.FeedBackType.UNUSUAL);
                                        } else if (typeStr.equals("COMPLETED")) {
                                            engineeringDailyFeedBackBean.setType(CommonEnum.FeedBackType.COMPLETED);
                                        }

                                    }
                                    String unusualDaysStr = engineeringDailyFeedbackListJsonObj.getString("unusualDays");
                                    if (null != unusualDaysStr && !TextUtils.isEmpty(unusualDaysStr) && !"null".equals(unusualDaysStr)) {
                                        engineeringDailyFeedBackBean.setUnusualDays(Integer.parseInt(unusualDaysStr));
                                    }
                                    engineeringDailyFeedBackBean.setUnusualReason(engineeringDailyFeedbackListJsonObj.getString("unusualReason"));
                                    String unusualStatusStr = engineeringDailyFeedbackListJsonObj.getString("unusualStatus");
                                    if (!TextUtils.isEmpty(unusualStatusStr)) {
                                        if (unusualStatusStr.equals("WAIT_CONFIRM")) {
                                            engineeringDailyFeedBackBean.setUnusualStatus(CommonEnum.UnusualStatus.WAIT_CONFIRM);
                                        } else if (unusualStatusStr.equals("WAIT_REPLY")) {
                                            engineeringDailyFeedBackBean.setUnusualStatus(CommonEnum.UnusualStatus.WAIT_REPLY);
                                        } else if (unusualStatusStr.equals("WAIT_REPLY_CONFIRM")) {
                                            engineeringDailyFeedBackBean.setUnusualStatus(CommonEnum.UnusualStatus.WAIT_REPLY_CONFIRM);
                                        } else if (unusualStatusStr.equals("REPLY_CONFIRM_FINISH")) {
                                            engineeringDailyFeedBackBean.setUnusualStatus(CommonEnum.UnusualStatus.REPLY_CONFIRM_FINISH);
                                        }

                                    }


                                    dailyFeedBackBeenList.add(engineeringDailyFeedBackBean);

                                }
                                orderBean.setEngineeringDailyFeedbackList(dailyFeedBackBeenList);


                            }
                            orderBean.setEngineeringName(dataJsonObj.getString("engineeringName"));

                            String finishDateStr = dataJsonObj.getString("finishDate");
                            if (!TextUtils.isEmpty(finishDateStr) && !finishDateStr.equals("null")) {
                                orderBean.setFinishDate(Long.parseLong(finishDateStr));
                            }

                            orderBean.setHasPauseOrder(dataJsonObj.getBoolean("hasPauseOrder"));

                            orderBean.setId(dataJsonObj.getString("id"));

                            String lastPauseDateStr = dataJsonObj.getString("lastPauseDate");
                            if (!TextUtils.isEmpty(lastPauseDateStr) && !lastPauseDateStr.equals("null")) {
                                orderBean.setLastPauseDate(Long.parseLong(lastPauseDateStr));
                            }

                            String latStr = dataJsonObj.getString("lat");
                            if (!TextUtils.isEmpty(latStr)) {
                                orderBean.setLat(Double.parseDouble(latStr));
                            }

                            String lonStr = dataJsonObj.getString("lon");
                            if (!TextUtils.isEmpty(lonStr)) {
                                orderBean.setLon(Double.parseDouble(lonStr));
                            }


                            String picUrlArrStr = dataJsonObj.getString("picUrl");
                            if (null != picUrlArrStr && !picUrlArrStr.equals("null") && !TextUtils.isEmpty(picUrlArrStr)) {
                                JSONArray picUrlArr = new JSONArray(picUrlArrStr);

                                List<String> picUrlLs = new ArrayList<String>();
                                for (int i = 0; i < picUrlArr.length(); i++) {
                                    picUrlLs.add(picUrlArr.getString(i));
                                }
                                orderBean.setPicUrl(picUrlLs);
                            }


                            String productListJsonArrStr = dataJsonObj.getString("productList");
                            if (null != productListJsonArrStr && !productListJsonArrStr.equals("null") && !TextUtils.isEmpty(productListJsonArrStr)) {
                                JSONArray productListJsonArr = new JSONArray(productListJsonArrStr);
                                List<ProductBean> productBeenLs = new ArrayList<ProductBean>();
                                for (int i = 0; i < productListJsonArr.length(); i++) {
                                    ProductBean productBean = new ProductBean();
                                    JSONObject productListJsonObj = (JSONObject) productListJsonArr.get(i);
                                    String amountStr = productListJsonObj.getString("amount");
                                    if (null != amountStr && !TextUtils.isEmpty(amountStr) && !"null".equals(amountStr)) {
                                        productBean.setAmount(Integer.parseInt(amountStr));
                                    }
                                    productBean.setId(productListJsonObj.getString("id"));
                                    productBean.setInstallDesc(productListJsonObj.getString("installDesc"));
                                    productBean.setInstallPosition(productListJsonObj.getString("installPosition"));
                                    productBean.setName(productListJsonObj.getString("name"));

                                    String picUrlJsonArrStr = productListJsonObj.getString("picUrl");
                                    if (null != picUrlJsonArrStr && !picUrlJsonArrStr.equals("null") && !TextUtils.isEmpty(picUrlJsonArrStr)) {
                                        JSONArray picUrlJsonArr = new JSONArray(picUrlJsonArrStr);
                                        List<String> picUrlLs = new ArrayList<String>();
                                        for (int j = 0; j < picUrlJsonArr.length(); j++) {
                                            picUrlLs.add(picUrlJsonArr.getString(j));
                                        }
                                        productBean.setPicUrl(picUrlLs);
                                    }


                                    JSONObject shapeTypeJsonObj = productListJsonObj.getJSONObject("shapeType");
                                    if (null != shapeTypeJsonObj) {
                                        productBean.setBorder(shapeTypeJsonObj.getInt("border"));
                                        productBean.setBorderBottom(shapeTypeJsonObj.getInt("borderBottom"));
                                        productBean.setBorderLeft(shapeTypeJsonObj.getInt("borderLeft"));
                                        productBean.setBorderRight(shapeTypeJsonObj.getInt("borderRight"));
                                        productBean.setBorderTop(shapeTypeJsonObj.getInt("borderTop"));
                                        productBean.setDesc(shapeTypeJsonObj.getString("desc"));
                                        productBean.setDiameter(shapeTypeJsonObj.getInt("diameter"));
                                        productBean.setHeight(shapeTypeJsonObj.getInt("height"));
                                        productBean.setThick(shapeTypeJsonObj.getInt("thick"));
                                        String typeStr = shapeTypeJsonObj.getString("type");
                                        if (!TextUtils.isEmpty(typeStr)) {
                                            if (typeStr.equals("ROUND")) {
                                                productBean.setType(CommonEnum.ProductShapeType.ROUND);
                                            } else if (typeStr.equals("RECTANGLE")) {
                                                productBean.setType(CommonEnum.ProductShapeType.RECTANGLE);
                                            } else if (typeStr.equals("SPECIALSHAPE")) {
                                                productBean.setType(CommonEnum.ProductShapeType.SPECIALSHAPE);
                                            }
                                        }

                                        productBean.setWidth(shapeTypeJsonObj.getInt("width"));
                                    }

                                    productBean.setUnit(productListJsonObj.getString("unit"));

                                    productBeenLs.add(productBean);
                                }
                                orderBean.setProductList(productBeenLs);
                            }


                            orderBean.setProjectName(dataJsonObj.getString("projectName"));

                            String realCompleteDate = dataJsonObj.getString("realCompleteDate");
                            if (!TextUtils.isEmpty(realCompleteDate) && !realCompleteDate.equals("null")) {
                                orderBean.setRealCompleteDate(Long.parseLong(realCompleteDate));
                            }


                            String superAdminConfirmCompleteDate = dataJsonObj.getString("superAdminConfirmCompleteDate");
                            if (!TextUtils.isEmpty(superAdminConfirmCompleteDate) && !superAdminConfirmCompleteDate.equals("null")) {
                                orderBean.setSuperAdminConfirmCompleteDate(Long.parseLong(superAdminConfirmCompleteDate));
                            }


                            orderBean.setReceiveAccountId(dataJsonObj.getString("receiveAccountId"));
                            orderBean.setReceiveAccountName(dataJsonObj.getString("receiveAccountName"));
                            String receiveOrderTimeStr = dataJsonObj.getString("receiveOrderTime");
                            if (!TextUtils.isEmpty(receiveOrderTimeStr) && !receiveOrderTimeStr.equals("null")) {
                                orderBean.setReceiveOrderTime(Long.parseLong(receiveOrderTimeStr));
                            }
                            String sendOrderTimeStr = dataJsonObj.getString("sendOrderTime");
                            if (!TextUtils.isEmpty(sendOrderTimeStr) && !sendOrderTimeStr.equals("null")) {
                                orderBean.setSendOrderTime(Long.parseLong(sendOrderTimeStr));
                            }
                            String statusStr = dataJsonObj.getString("status");
                            if (!TextUtils.isEmpty(statusStr)) {
                                if (statusStr.equals("CREATED")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.CREATED);
                                } else if (statusStr.equals("SEND")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.SEND);
                                } else if (statusStr.equals("RECEIVED")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.RECEIVED);
                                } else if (statusStr.equals("RETURNED")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.RETURNED);
                                } else if (statusStr.equals("COMPLETED")) {
                                    orderBean.setStatus(CommonEnum.EngineeringOrderStatus.COMPLETED);
                                }
                            }

                            engineeringInstallOrderDetailListener.successed(orderBean);

                        } else {
                            String error_str = code;
                            error_str += "," + ConstantUtil.getErrorCode(code);
                            if (!json.isNull("error_str")) {
                                error_str += "," + json.getString("error_str");
                            }
                            engineeringInstallOrderDetailListener.failed(error_str);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {

                }
            }
        }).start();
    }

    public interface OnEngineeringInstallOrderDetailListener {
        void successed(EngineeringInstallationOrderBean engineeringInstallationOrderBean);

        void failed(String desc);
    }

}
